package urban;

import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;

public class DataStore {
	
	private static final String DBFILENAME = "urbansearch.db4o";

	public boolean store(Object o) {
		ObjectContainer db = Db4o.openFile(DBFILENAME);
		boolean success = false;
		try {
			db.store(o);
			success = true;
		} catch (Exception e) {
			// do nothing, will return false
		} finally {
			db.close();
		}
		return success;
	}
	
	public ObjectSet<Object> retrieveFromTemplate(Object template) {
		ObjectContainer db = Db4o.openFile(DBFILENAME);
		try {
			return db.queryByExample(template);
		} catch (Exception e) {
			// do nothing, will return null
		} finally {
			db.close();
		}
		return null;
	}
}
